﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="TreatmentsView.xaml.cs" company="ELEN 7045 GROUP II">>
//   Contributed by E.Vosloo
// </copyright>
// <summary>
//   Interaction logic for TreatmentsView.xaml
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Presentation.Module.StudyDefinition.Views
{
    #region

    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;

    using Presentation.Module.StudyDefinition.Interfaces.ViewModels;
    using Presentation.Module.StudyDefinition.Interfaces.Views;
    using Presentation.Shell.Interfaces;

    #endregion

    /// <summary>
    /// Interaction logic for TreatmentsView.xaml
    /// </summary>
    public partial class TreatmentsView : UserControl, ITreatmentsView
    {
        #region Constants and Fields

        /// <summary>
        /// View Model Instance
        /// </summary>
        private readonly ITreatmentsViewModel treatmentsViewModelInstance;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="TreatmentsView"/> class.
        /// </summary>
        /// <param name="treatmentsViewModel">
        /// treatments view model.
        /// </param>
        public TreatmentsView(ITreatmentsViewModel treatmentsViewModel)
        {
            InitializeComponent();

            this.treatmentsViewModelInstance = treatmentsViewModel;
            this.treatmentsViewModelInstance.Initialize();
            this.DataContext = treatmentsViewModel;
            this.treatmentsViewModelInstance.View = this;

        }

        #endregion

        #region Events

        /// <summary>
        /// Occurs when [view exit].
        /// </summary>
        public event ViewExit ViewExit;

        #endregion

        #region Methods

        /// <summary>
        /// Cancels the specified sender.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.
        /// </param>
        private void Cancel(object sender, RoutedEventArgs e)
        {
            if (this.ViewExit != null)
            {
                this.ViewExit.Invoke();
            }
        }

        /// <summary>
        /// The update controls.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void UpdateControls(object sender, RoutedEventArgs e)
        {
            BindingExpression bindExp = ((ItemsControl)e.OriginalSource).GetBindingExpression(ItemsControl.ItemsSourceProperty);

            bindExp.UpdateSource();
            bindExp.UpdateTarget();
            this.InvalidateVisual();
        }

        #endregion
    }
}
